package com.lollipop.programming;

import lombok.extern.slf4j.Slf4j;

import java.util.Arrays;

/**
 * @Author Lollipop
 * @Date 2025/4/7 16:15
 * @Description 判断两个数组是否包含相同元素
 */
@Slf4j
public class ArrEqual {
    public static void main(String[] args) {
        int[] arr1 = {1, 2, 3, 4, 5};
        int[] arr2 = {1, 2, 4, 3, 5};
        int[] arr3 = {1, 2, 3, 4};
        log.info("arr1和arr2是否相等：{}", isEqual(arr1, arr2));
    }

    private static boolean isEqual(int[] arr1, int[] arr2) {
        if (arr1.length != arr2.length) {
            return false;
        }
        // 对数组进行排序
        Arrays.sort(arr1);
        Arrays.sort(arr2);
        // 比较数组是否相等
        return Arrays.equals(arr1, arr2);
    }
}